package com.example.myapplication1.threademo.cutdownlatchtest;

import java.util.concurrent.CountDownLatch;

/**
 * Copyright (C), 2020, 重庆八进制有限公司
 *
 * @author: weng
 * @last-modifier: weng
 * @version: 1.0
 * @create-date: 2020/12/3 11:14
 * @last-modify-date: 2020/12/3 11:14
 * @description:
 */
public abstract class AbstractService {

    private boolean isSuccess;
    private CountDownLatch countDownLatch;


    public AbstractService(CountDownLatch countDownLatch){
        this.countDownLatch = countDownLatch;
    }
    public abstract boolean dotask();

    public boolean checkState() {

        return isSuccess;
    }

    public boolean start() {

        new Thread() {
            @Override
            public void run() {
                try {
                    isSuccess = dotask();
                }finally {
                    countDownLatch.countDown();
                }
            }
        }.start();

        return isSuccess;
    }

}
